package tests.user;

import tester.*;

/**
 * Copyright 2007, 2008 Viera K. Proulx
 * This program is distributed under the terms of the 
 * GNU Lesser General Public License (LGPL)
 */

/*
   +--------------+    
   | Book         |    
   +--------------+    
   | String title |     
   | String author|    
   | int    year  |      
   +--------------+    
 */  

/**
 * A class to represent a book with an author.
 * An example of a class with containment.
 * 
 * @author Viera K. Proulx
 * @since 30 May 2007
 */
public class Book implements ISame<Book>
{
  /** the title of the book */
  public String title;
  /** the author of the book - an instance of 
   * <CODE>{@link Author Author}</CODE> class */
  protected Author author;
  /** the year of publication */
  protected int    year;

  /**
   * The standard full constructor
   * @param title the tile of the book
   * @param author the author of the book
   * @param year the year of publication
   */
  public Book(String title, Author author, int year){
    this.title=title;
    this.author=author;
    this.year=year;
  }
  
  /**
   * Method to use in tests - change the 
   * <CODE>{@link Author Author}</CODE> of this book to the given one.
   * 
   * @param auth the given author
   * @return new book with real author as given
   */
  public Book changeAuthor(Author auth){
    return new Book(this.title, auth, this.year);
  }
  
  /**
   * Is this song the same as that book?
   * 
   * @param that the book to compare with
   * @return true if this book is the same as that book
   */
  public boolean same(Book that){
    return 
      this.title.equals(that.title) &&
      this.author.same(that.author) &&
      this.year == that.year;
  }
}      


